<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 文章管理
                </el-breadcrumb-item>
                <el-breadcrumb-item>发布文章</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="form-box">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="文章标题">
                        <el-input v-model="form.title"></el-input>
                    </el-form-item>
                    <el-form-item label="文章分类">
                        <el-input v-model="form.categories"></el-input>
                    </el-form-item>
                    <el-form-item label="文章标签">
                        <el-input v-model="form.tags"></el-input>
                    </el-form-item>
                    <el-form-item label="url" prop="tags">
                        <el-input v-model="form.articlePicUrl"></el-input>
                    </el-form-item>
                    <el-form-item label="文本框">
                        <mavon-editor v-model="form.content"/>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">表单提交</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    import { mavonEditor } from 'mavon-editor'
    import 'mavon-editor/dist/css/index.css'
    export default {
        name: 'EditArticle',
        components:{mavonEditor},
        data() {
            return {
                form: {
                    articleId:'',
                    title: '',
                    categories: '',
                    tags: '',
                    context: '',
                    articlePicUrl: ""

                }
            };
        },
        methods: {
            onSubmit() {
                const _this=this
                this.$axios.post("http://39.106.115.234:8083/article/edit",this.form,{
                    headers:{
                        "Authorization":localStorage.getItem("token")
                    }
                }).then(res=>{
                    // console.log(res.data)
                    _this.$message.success(res.data.message)
                    _this.$router.push("/table")
                })
                // this.$message.success('提交成功！');
            },
            getAll(){
                console.log(this.$route.params.articleId)
                const _this=this
                this.$axios.get("http://39.106.115.234:8083/article/detail/"+this.$route.params.articleId).then(res=>{
                    console.log(res.data.data)
                    console.log(_this.form)
                    _this.form.title=res.data.data.title
                    _this.form.categories=res.data.data.categories
                    _this.form.tags=res.data.data.tags
                    _this.form.content=res.data.data.content
                    _this.form.articleId=res.data.data.articleId
                    _this.form.articlePicUrl=res.data.data.articlePicUrl
                    console.log(_this.form)
                })

            }
        },
        created() {
            this.getAll()
        },
        watch:{
            $route(to,from){
                this.getAll()
            }
        }
    };
</script>

<style>

</style>



